//
//  LCLoginViewController.m
//  lechuang
//
//  Created by Mr_hi on 2023/3/23.
//  Copyright © 2023 Mooyi. All rights reserved.
//

#import "LCLoginViewController.h"
#import "LCLoginService.h"

#import "LCTabBarViewController.h"
#import "XWXAllXieYiController.h"

#import "LCRegisterViewController.h"
#import "LCVerificationViewController.h"

@interface LCLoginViewController ()

@property (weak, nonatomic) IBOutlet UITextField *mobTfl;
@property (weak, nonatomic) IBOutlet UITextField *passTfl;

@property (weak, nonatomic) IBOutlet UIButton *agreeBtn;

@end

@implementation LCLoginViewController

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:animated];
}

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (IBAction)agreeBtnAction:(UIButton *)sender {
    sender.selected = !sender.selected;
}

- (IBAction)lookXieYiAction:(UIButton *)sender {
    XWXAllXieYiController *webVC = [XWXAllXieYiController new];
    webVC.tileStr = @"《用户协议》";
    webVC.urlStr = URLSingleWeb(@"1000007");
    [self presentViewController:webVC animated:YES completion:nil];
}

- (IBAction)lookYinSiAction:(UIButton *)sender {
    XWXAllXieYiController *webVC = [XWXAllXieYiController new];
    webVC.tileStr = @"《隐私协议》";
    webVC.urlStr = URLSingleWeb(@"1000006");
    [self presentViewController:webVC animated:YES completion:nil];
}

- (IBAction)loginBtnAction:(UIButton *)sender {
//    NSString *udid = LCUserDefGet(XWX_udid);
//    if (!udid) {
//        // 去下载SSL证书的描述文件，来获取udid
//        [LCFunction downloadConfig];
//    } else {
        // 注册
        if (self.mobTfl.text.length <= 0) {
            [self showErrorText:self.mobTfl.placeholder];
        } else if ([NSString isMobileNumber:self.mobTfl.text] == NO) {
            [self showErrorText:@"请输入正确格式的手机号"];
        } else if (self.passTfl.text.length <= 0) {
            [self showErrorText:self.passTfl.placeholder];
//        } else if (self.agreeBtn.isSelected == NO) {
//            [self showErrorText:@"请勾选同意《用户协议》和《隐私政策》"];
        } else {
            [LCLoginService loginWithMobStr:self.mobTfl.text Password:self.passTfl.text Block:^(BOOL isSuccess) {
                if (isSuccess) {
                    [self.window setBackgroundColor:[UIColor whiteColor]];
                    LCTabBarViewController *tabbar = [[LCTabBarViewController alloc] init];
                    self.window.rootViewController = tabbar;
                    [self.window makeKeyAndVisible];
                }
            }];
        }
//    }
}

- (IBAction)registerBtnAction:(UIButton *)sender {
    LCRegisterViewController * pushVC = [LCRegisterViewController xx_instantiateFromStoryboardNamed:@"Login"];
    pushVC.window = self.window;
    [self.navigationController pushViewController:pushVC animated:YES];
}

- (IBAction)forgotPswdBtnAction:(UIButton *)sender {
    LCVerificationViewController * pushVC = [LCVerificationViewController xx_instantiateFromStoryboardNamed:@"Login"];
    [self.navigationController pushViewController:pushVC animated:YES];
}

@end
